package com.fr.data;

import com.fr.base.FCloneable;
import com.fr.base.XMLable;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLableReader;
import com.fr.data.core.DataXMLUtils;
import com.fr.data.impl.CustomDictionary;
import com.fr.data.impl.DatabaseDictionary;
import com.fr.data.impl.NameDatabaseConnection;
import com.fr.report.script.Calculator;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class Semantic
  implements Cloneable, Serializable, XMLable
{
  private Dictionary dictionary;

  public void setDictionay(Dictionary paramDictionary)
  {
    this.dictionary = paramDictionary;
  }

  public Dictionary getDictionary()
  {
    return this.dictionary;
  }

  public Object getSemanticName(String paramString, Calculator paramCalculator)
  {
    if (this.dictionary != null)
    {
      if ((this.dictionary instanceof DatabaseDictionary) && (((DatabaseDictionary)this.dictionary).getDatabaseConnection() instanceof NameDatabaseConnection) && (((NameDatabaseConnection)((DatabaseDictionary)this.dictionary).getDatabaseConnection()).getName() == null))
        return null;
      return this.dictionary.get(paramString, paramCalculator);
    }
    return null;
  }

  public JSONObject createJSON()
    throws Exception
  {
    if (!(this.dictionary instanceof DatabaseDictionary))
      return null;
    return ((DatabaseDictionary)this.dictionary).createJSON();
  }

  public void parseJSON(JSONObject paramJSONObject)
    throws Exception
  {
    if (paramJSONObject == null)
      return;
    DatabaseDictionary localDatabaseDictionary = new DatabaseDictionary();
    localDatabaseDictionary.parseJSON(paramJSONObject);
    setDictionay(localDatabaseDictionary);
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isAttr())
      this.dictionary = null;
    if (paramXMLableReader.isChildNode())
    {
      String str = paramXMLableReader.getTagName();
      if (("Dictionary".equals(str)) || ("Dict".equals(str)))
      {
        this.dictionary = DataXMLUtils.readXMLDictionary(paramXMLableReader);
      }
      else if ("ColumnMap".equals(str))
      {
        CustomDictionary localCustomDictionary = new CustomDictionary();
        ArrayList localArrayList1 = new ArrayList();
        ArrayList localArrayList2 = new ArrayList();
        paramXMLableReader.readXMLObject(new XMLReadable(this, localArrayList1, localArrayList2)
        {
          private final List val$keyList;
          private final List val$valueList;
          private final Semantic this$0;

          public void readXML()
          {
            if ("Column".equals(paramXMLableReader.getTagName()))
            {
              String str;
              Object localObject1 = null;
              Object localObject2 = null;
              if ((str = paramXMLableReader.getAttr("name")) != null)
                localObject1 = str;
              if (localObject1 == null)
                return;
              if ((str = paramXMLableReader.getAttr("semantic")) != null)
                localObject2 = str;
              this.val$keyList.add(localObject1);
              this.val$valueList.add(localObject2);
            }
          }
        });
        localCustomDictionary.setKV(localArrayList1.toArray(), localArrayList2.toArray());
        if (localCustomDictionary.size() > 0)
          this.dictionary = localCustomDictionary;
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    if (this.dictionary != null)
      DataXMLUtils.writeXMLDictionary(paramXMLPrintWriter, this.dictionary);
  }

  public boolean equals(Object paramObject)
  {
    return ((paramObject instanceof Semantic) && (super.equals(paramObject)) && (ComparatorUtils.equals(this.dictionary, ((Semantic)paramObject).dictionary)));
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    Semantic localSemantic = (Semantic)super.clone();
    if (this.dictionary != null)
      localSemantic.setDictionay((Dictionary)this.dictionary.clone());
    return localSemantic;
  }
}